package com.lovo.pis.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lovo.pis.constant.MessageCode;
import com.lovo.pis.dto.*;
import com.lovo.pis.service.IStockGoodsService;
import com.lovo.pis.service.ISupplierService;
import com.lovo.pis.utils.JsonResult;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/stockGoods")
public class StockGoodsController {

    @Autowired
    IStockGoodsService stockGoodsService;

    //id查询商品
    @RequestMapping("/query")
    public StockGoodsBean queryById(int id){
        return stockGoodsService.queryById(id);
    }

    //id修改商品售价
    @RequestMapping("/change")
    public JsonResult changeById(@RequestBody StockGoodsBean stockGoodsBean){
        JsonResult jsonResult = new JsonResult<>();
         stockGoodsService.changeById(stockGoodsBean);
        return jsonResult;
    }

    //模糊分页查询所有库存商品信息 销售出库中添加商品时也使用该接口
    @RequestMapping("/queryAll")
    public IPage<StockGoodsBean> queryAllStockGoods(@RequestBody PageBean<StockGoodsBean> pageInfo){
       return stockGoodsService.queryAllStockGoods(pageInfo);
    }

    //入库操作
    @RequestMapping("/inStock")
    public JsonResult inStock(String supplierName,String buyer,int carId){
        JsonResult jsonResult = new JsonResult<>();
        stockGoodsService.inStock(supplierName,buyer,carId);
        return jsonResult;
    }
    //出库操作
    @RequestMapping("/outStock")
    public JsonResult outStock(String customName,String seller,double price,String address,int carId){
        JsonResult jsonResult = new JsonResult<>();
        stockGoodsService.outStock(customName,seller,price,address,carId);
        return jsonResult;
    }
}
